import type { DetailsResponse, ListResponse, Response } from '@/http';
import { request } from '@/http';
import type {
  ICuisine,
  IRestaurant,
  IRestaurantListItem,
  IListItemV2,
  IRestaurantTimeList
} from './interfaces/restaurants';

/**
 * 菜品列表
 * @returns 菜品列表
 */
export function getCuisines() {
  return request.post<ListResponse<ICuisine>>('/food/restaurant/getCuisineList');
}

/**
 * 日期列表
 * @param id 餐厅 ID
 * @returns 日期列表
 */
export function getDates(id: number) {
  return request.post<ListResponse<string>>('/food/restaurant/getDateList', { id });
}

/**
 * 餐厅列表 V2
 * @param cuisineIds 菜品 ID 数组
 * @returns 餐厅列表
 */
export function getRestaurantsV2(cuisineIds?: string) {
  return request.post<ListResponse<IListItemV2>>('/food/restaurant/getListV2', {
    cuisineIds
  });
}

/**
 * 餐厅列表
 * @deprecated 请使用 getRestaurantsV2
 */
export function getRestaurants(payload: {
  activityId: number;
  pagination: boolean;
  page?: number;
  pageSize?: number;
}) {
  return request.post<ListResponse<IRestaurantListItem>>('/food/restaurant/getList', payload);
}

/**
 * 餐厅详情
 */
export function getRestaurant(id: number, date: string) {
  return request.post<DetailsResponse<IRestaurant>>('/food/restaurant/getDetail', { id, date });
}

/**
 * 检查库存
 */
export function checkInventory(id: number, date: string, booking_count: number) {
  return request.post<Response<IRestaurantTimeList>>('/food/restaurant/checkStocks', {
    id,
    date,
    booking_count
  });
}

/**
 * 收藏
 */
export function favorite(restaurantId: number) {
  return request.post<Response>('/food/restaurant/collect', { restaurantId });
}

/**
 * 取消收藏
 */
export function unfavorite(restaurantId: number) {
  return request.post<Response>('/food/restaurant/cancelCollect', { restaurantId });
}
